<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="${css}/pintuer.css">
    <link rel="stylesheet" href="${css}/admin.css">
    <link rel="stylesheet" href="${css}/bootstrap.css">
    <script src="${js}/jquery.js"></script>
    <script src="${js}/pintuer.js"></script>
    <script src="${js}/bootstrap.js"></script>
</head>
<body>
<div class="panel admin-panel margin-top">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>类型添加</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="${root}/category/add">
            <input type="hidden" class="input w50" name="stated" value="0" />
            <div class="form-group">
                <div class="label">
                    <label>类型名:</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" name="cname" value="" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>类型描述:</label>
                </div>
                <div class="field">
                    <textarea name="description" class="form-control"  placeholder="请填写类型描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit">提交</button>
                </div>
            </div>
            <span class="text-red-light">${categoryAddInfo}</span>
        </form>

        <table class="table table-bordered">
            <caption>类型信息</caption>
            <thead>
            <tr>
                <th>序号</th>
                <th>状态</th>
                <th>类型</th>
                <th>类型描述</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                <c:forEach items="${categorysAll}" var="data" varStatus="v">
                        <tr>
                            <td>
                                ${v.count}
                            </td>
                            <td>
                                <select name="stated">
                                    <option value="0" <c:if test="${data.stated==0}">selected</c:if> >已上架</option>
                                    <option value="1" <c:if test="${data.stated==1}">selected</c:if> >已下架</option>
                                </select>
                            </td>
                            <td>
                                <input class="input_opt" type="text" name="cname" value="${data.cname}"/>
                            </td>
                            <td>
                                <textarea name="description" class="form-control input_textarea" value="${data.description}">${data.description}</textarea>
                            </td>
                            <td>
                                <button type="button" class="btn btn-warning update" name="${data.cid}">修改</button>
                            </td>
                        </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
</div>
<script>
    $(function(){
        $(".input_opt").change(function () {
            $(this).attr('value',$(this).val());
        });

        $(".input_textarea").change(function () {
            $(this).attr('value',$(this).val());
        });

        $(".update").click(function () {
            var cid = $(this).attr('name');
            var stated = $(this).parent().prev().prev().prev().children().val();
            var cname = $(this).parent().prev().prev().children().attr('value');
            var description = $(this).parent().prev().children().attr('value');
            var url="${root}/category/update";
            var obj = {"cid":cid,"cname":cname,"description":description,"stated":stated};
            if (confirm("是否修改该数据")){
                $.ajax({
                   url:url,
                   type:"post",
                   data:JSON.stringify(obj),
                   contentType:"application/json",
                   dataType:"json",
                   success:function (result) {
                        if(result.updateInfo==100){
                            alert("修改成功!");
                        }
                   }
                });
            }
        });

        <%--$(".delete").click(function () {--%>
        <%--    var cid = $(this).attr('name');--%>
        <%--    var url="${root}/category/delete";--%>
        <%--    var reObj=$(this).parent().parent();--%>
        <%--    if (confirm("是否删除该数据")){--%>
        <%--        $.ajax({--%>
        <%--            url:url,--%>
        <%--            type:"post",--%>
        <%--            data:JSON.stringify({"cid":cid}),--%>
        <%--            contentType:"application/json",--%>
        <%--            dataType:"json",--%>
        <%--            success:function (result) {--%>
        <%--                if(result.deleteInfo==100){--%>
        <%--                    reObj.remove();--%>
        <%--                    alert("删除成功!");--%>
        <%--                }--%>
        <%--            }--%>
        <%--        });--%>
        <%--    }--%>
        <%--});--%>
    })
</script>
</body>
</html>
